package com.two.screen.water.balance.utils

import android.annotation.SuppressLint
import com.lzy.okgo.model.HttpHeaders
import com.lzy.okgo.model.HttpParams
import com.two.screen.water.balance.net.api.DataApi
import java.util.*

/**
 * 创建者     Noel
 * 创建时间   2018/1/8 9:51
 * 描述	      url请求地址。
 */

object Params {

    const val mPerBannerImgStayTimeIndex: String = "mPerBannerImgStayTimeIndex" //0, 15, 30, 60, 120, 300, 600
    const val mIntoBannerTimeIndex: String = "mIntoBannerTimeIndex" //0, 15, 30, 60, 120, 300, 600
    const val mBannerPlayTypeIndex: String = "mBannerPlayTypeIndex" //0图片和视频循环轮播", "1仅播放图片", "2仅播放视频
    const val mAiBrandTypeIndex: String = "mAiBrandTypeIndex" //0不是用, "1食方科技", "2由由科技","3银歌"
    const val mPrinterTypeIndex: String = "mPrinterTypeIndex" //0不使用;1AutoReplyPrint
    const val mReaderIndex: String = "mReaderIndex" //读卡器串口
    const val mPrintPaperWidthIndex: String = "mPrintPaperWidthIndex" //0-58mm;1-80mm
    const val mBillPrintTimesIndex: String = "mBillPrintTimesIndex" //0-1；1-2；2-3；
    const val mScaleTypeIndex: String = "mScaleTypeIndex" //0不使用；1超赢电子秤；2七华电子秤；
    const val isAutoJiaoJiePrint: String = "isAutoJiaoJiePrint"
    const val isAutoPayPrint: String = "isAutoPayPrint"
    const val mIsShowViceDisplay: String = "mIsShowViceDisplay"
    const val mIsShowBatteryChanged: String = "mIsShowBatteryChanged"
    const val mIsOpenPayVoice: String = "mIsOpenPayVoice"
    const val mIsShowBluetoothPrinter: String = "mIsShowBluetoothPrinter"
    const val mIsShowViceBanner: String = "mIsShowViceBanner"
    const val ServerGoodsJson: String = "ServerGoodsJson"
    const val IndexBeanJson: String = "IndexBeanJson"
    const val list: String = "list"
    const val vals: String = "vals"
    const val Brand_Type: String = "Brand_Type"
    const val mBluetoothPrinterMac: String = "mBluetoothPrinterMac"
    const val mBluetoothPrinterName: String = "mBluetoothPrinterName"
    const val mSerialPortPath: String = "mSerialPortPath"
    const val mSerialPortPort: String = "mSerialPortPort"
    const val mSerialPortPathReader: String = "mSerialPortPathReader"
    const val mSerialPortPortReader: String = "mSerialPortPortReader"
    const val mUSBDevicePath: String = "mUSBDevicePath"
    const val mWeightSerialPortPath: String = "mWeightSerialPortPath"
    const val mReaderSerialPortPath: String = "mReaderSerialPortPath"
    const val price: String = "price"
    const val item_type: String = "item_type"
    const val mStoreNo: String = "mStoreNo"//食方  帐号
    const val mLicenseNo: String = "mLicenseNo"//食方  授权码
    const val mStoreName: String = "mStoreName"//食方  档口名称
    const val mCdKeyYGEt: String = "mCdKeyYGEt"//银歌
    const val mCdKeyCZEt: String = "mCdKeyCZEt"//创智
    const val mCdKeyEt: String = "mCdKeyEt"
    const val isPublic: String = "isPublic"
    const val mContactNameEt: String = "mContactNameEt"
    const val mContactTelEt: String = "mContactTelEt"
    const val deviceCode: String = "deviceCode"
    const val mApiUrl: String = "mApiUrl"
    const val sc_n: String = "sc_n"
    const val mImageUrl: String = "mImageUrl"
    const val pwd: String = "pwd"
    const val num: String = "num"
    const val msm: String = "msm"
    const val update_version: String = "update_version"
    const val mar_id: String = "mar_id"
    const val merchant_id: String = "merchant_id"
    const val goods_id: String = "goods_id"
    const val sort: String = "sort"
    const val cate: String = "cate"
    const val mProductListJson: String = "mProductListJson"
    const val isRememberPwd: String = "isRememberPwd"
    const val mCateListJson: String = "mCateListJson"
    const val version: String = "version"
    const val grossWeight: String = "grossWeight"
    const val weight: String = "weight"
    const val content: String = "content"
    const val unitPrice: String = "unitPrice"
    const val money: String = "money"
    const val tempOrderId: String = "tempOrderId"
    const val wx_pay_qrcode: String = "wx_pay_qrcode"
    const val qrcode: String = "qrcode"
    const val data_json: String = "data_json"
    const val skinWeight: String = "skinWeight"
    const val mer_id: String = "mer_id"
    const val stall_id: String = "stall_id"
    const val stall_name: String = "stall_name"
    const val order_sn: String = "order_sn"
    const val quantity: String = "quantity"
    const val result: String = "result"
    const val productId: String = "productId"
    const val productBatchId: String = "productBatchId"
    const val orderSource: String = "orderSource"
    const val wxapp_id_value = 10001
    const val page_size: String = "page_size"
    const val params: String = "params"
    const val src: String = "src"
    const val user_id: String = "user_id"
    const val user_name: String = "user_name"
    const val describe: String = "describe"
    const val date: String = "date"
    const val com_id: String = "com_id"

    const val pay_t: String = "pay_t"
    const val d_price: String = "d_price"
    const val d_c: String = "d_c"
    const val gd_price: String = "gd_price"
    const val diff_price: String = "diff_price"
    const val data: String = "data"
    const val wg: String = "wg"
    const val card: String = "card"
    const val c_time: String = "c_time"
    const val od_n: String = "od_n"
    const val size: String = "size"
    const val page: String = "page"
    const val auth_code: String = "auth_code"
    const val time_begin: String = "time_begin"
    const val time_end: String = "time_end"
    const val ids: String = "ids"
    const val date_begin: String = "date_begin"
    const val code: String = "code"
    const val id: String = "id"
    const val tp: String = "tp"
    const val card_n: String = "card_n"
    const val scale_sn: String = "scale_sn"
    const val tel: String = "tel"
    const val password: String = "password"
    const val role: String = "role"
    const val lastmonth: String = "lastmonth"
    const val yesterday: String = "yesterday"
    const val month: String = "month"
    const val mobile: String = "mobile"
    const val today: String = "today"
    const val status: String = "status"
    const val start_time: String = "start_time"
    const val end_time: String = "end_time"
    const val pay_type: String = "pay_type"
    const val phone: String = "phone"
    const val bazaarId: String = "bazaarId"
    const val url: String = "url_vertical"
    const val sign: String = "sign"
    const val client_type: String = "client_type"
    const val username: String = "username"
    const val token: String = "token"
    const val cate_id: String = "cate_id"
    const val mIsOpenVoiceBroadcastSw: String = "mIsOpenVoiceBroadcastSw"
    const val mIsOpenPrintSw: String = "mIsOpenPrintSw"

    const val mPrintTimesEt: String = "mPrintTimesEt"
    const val app_name: String = "app_name"
    const val merchantId: String = "merchantId"
    const val kind: String = "kind"
    const val app_address: String = "app_address"
    const val type: String = "type"
    const val type_id: String = "type_id"
    const val task_type: String = "task_type"
    const val image: String = "image"
    const val buyerId: String = "buyerId"
    const val packageName: String = "packageName"
    const val com_type_child: String = "com_type_child"
    const val scale: String = "scale"
    const val level: String = "level"
    const val name: String = "name"
    const val Authorization: String = "Authorization"
    const val beginDate: String = "beginDate"
    const val endData: String = "endData"
    const val sex: String = "sex"
    const val child: String = "child"
    const val authCode: String = "authCode"
    const val discountMoney: String = "discountMoney"
    const val detailList: String = "detailList"

    const val key: String = "key"
    const val search: String = "search"
    const val payType: String = "payType"


    const val unit: String = "unit"
    const val spec: String = "spec"
    const val sale_price: String = "sale_price"
    const val IV_SPLICT_ADD = "|"
    const val IV_SPLICT_SHOW = "\\" + IV_SPLICT_ADD

    /*新参数*/
    fun getParams(map: SortedMap<String, Any?>, isSign: Boolean = true): HttpParams {
        map[client_type] = 46
        return HttpParams().apply {
            put(Params.sign, getSign(map))
        }
    }

    /*请求头
    *   token 用户登录口令
        role_type int 角色[1监管、2协管、3企业]为企业单位ID]
        type_id 对应角色的类型[role_type=1 则值为1市局、2分局、3监管所、4社区；role_type=2 则值为1物业 、2巡查机构、3检测机构、4总部；role_type=3 则值为0]
        model_type 场景[role_type=1或3，则值为1餐饮、2农贸市场；role_type=2且type_id=1 则值为1餐饮、2 农贸市场；其它则值为0]
        version 当前版本号
        role_id int 对应角色的单位ID[role_type=1 则值为监管单位ID；role_type=2 则值为协管单位ID； role_type=3 则值
        device_type 设备类型[pc、ios、android]
        device_info 设备信息
    * */

    @SuppressLint("MissingPermission")
    fun getHeads(map: SortedMap<String, String?> = sortedMapOf()): HttpHeaders {
        return HttpHeaders().apply {
            put("Authorization", "Bearer ".plus(DataApi.mToken))
        }
    }

}

fun HttpParams.getSign(map: SortedMap<String, Any?>): String {
    return CommUtils.encodeByMD5(StringBuilder().let {
        for ((key, value) in map) {
            if (value != null && !value.toString().isBlank()) {
                it.append(key.toString())
                    .append("=")
                    .append(value)
                    .append("&")
                this.put(key.toString(), value.toString())
            }
        }
        //密钥
        if (it.isNotEmpty()) it.deleteCharAt(it.lastIndex)
        "qihua2022&".plus(it.toString())
            .apply {
                CommUtils.println("sign", "排序后：$this")
            }
    })
}

